#include "adddoc.h"
#include "ui_adddoc.h"
#include <QDebug>


AddDoc::AddDoc(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddDoc)
{
    ui->setupUi(this);
    sexBtn = new QButtonGroup();
    sexBtn->setExclusive(true);
    sexBtn->addButton(ui->sex_male, 0);
    sexBtn->addButton(ui->sex_female, 1);

    attBtn = new QButtonGroup();
    attBtn->setExclusive(true);
    attBtn->addButton(ui->atten_true, 1);
    attBtn->addButton(ui->atten_false, 0);

    freeBtn = new QButtonGroup();
    freeBtn->setExclusive(true);
    freeBtn->addButton(ui->free_true, 1);
    freeBtn->addButton(ui->free_false, 0);


}

AddDoc::~AddDoc()
{
    delete ui;
}

void AddDoc::setSQL(SQLConn *&conn)
{
    sql = conn;
}

void AddDoc::on_bt_confirm_clicked()
{
    m_name = ui->le_name->text();
    m_age = ui->sp_age->text().toInt();
    if (sexBtn->checkedId() == 0)
    {
        m_sex ="男";
    }
    else
    {
        m_sex ="女";
    }
    m_attendence = attBtn->checkedId();
    m_status = freeBtn->checkedId();
    m_work_age = ui->sp_work_age->text().toFloat();
    m_major = ui->le_major->text();
    m_phone = ui->le_phone->text();
    sql->add_doctor(m_name, m_age, m_sex, m_work_age, m_major, m_attendence, m_status, m_phone);
    this->close();
}

void AddDoc::on_bt_cancel_clicked()
{
    this->close();
}
